package controller.dialog;

import controller.KeyBordJogoEventos;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * Classe que gerencia as ofertas do jogador
 * Classe segue a implemetação do Patterne Singleton
 * @author Adriano
 */
public class DialogPopUpMenu {
    private static DialogPopUpMenu intancia;
    private static Stage s;
    private Parent root;
    
    public DialogPopUpMenu() {
        try{
            Screen screen = Screen.getPrimary();
            Rectangle2D bounds = screen.getVisualBounds();
            root = FXMLLoader.load(getClass().getResource("/view/Popupmenu.fxml"));
            Scene scene = new Scene(root,Color.web("0xdfdfdfee") );
            scene.setOnKeyPressed(new KeyBordJogoEventos());
            
            //Cliar a sena do dilog
            s = new Stage(StageStyle.TRANSPARENT);
            s.setScene(scene);
            s.initModality(Modality.APPLICATION_MODAL);
            s.setX((bounds.getWidth()/2)-250);
            s.setY(bounds.getHeight()-190);
        }catch(Exception e){}
    }
    
    /**Retornar a unica instância da classe*/
    public static DialogPopUpMenu getIntancia() {
        if (intancia == null) {
            intancia = new DialogPopUpMenu(); 
        }
        return intancia;
    }
    
    /**Exibir o dilog*/
    public void show(int id,String descricao){
        Label des = (Label) root.lookup("#message");
        des.setText(descricao);
        Label campoId = (Label) root.lookup("#id");
        campoId.setText(""+id);
        TextField valor = (TextField) root.lookup("#valor");
        valor.setText("");
        s.show();
    }
    
    /**Fechar o Dialog*/
    public void close(){
        s.close();
    }
}
